package com.laihui.viewholder;

import android.animation.ObjectAnimator;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.laihui.activity.R;

import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.laihui.entity.Index;
import com.laihui.entity.LoanBean;

import java.text.DecimalFormat;

/**
 * Created by chensk on 2017/12/11.
 */


public class IndexBorrowRecordViewHolder extends BaseViewHolder<LoanBean> {
   String TAG = "IndexBorrowRecordViewHolder";
   TextView tv_loan_name,tv_money,tv_time_limit,tv_apr;
   LinearLayout liner_loans;
    private ProgressBar pb;

    public IndexBorrowRecordViewHolder(ViewGroup parent) {
        super(parent, R.layout.item_index_fragment);
        tv_loan_name = $(R.id.tv_loan_name);
        tv_time_limit = $(R.id.tv_time_limit);
        tv_money = $(R.id.tv_money);
        tv_apr = $(R.id.tv_apr);
        liner_loans  =  $(R.id.liner_loans);
        pb = $(R.id.pb);

    }

    @Override
    public void setData(final LoanBean data) {
        DecimalFormat df = new DecimalFormat("0.00");
        tv_loan_name.setText(data.name+"");
        tv_apr.setText(df.format(data.apr)+"%");
        if (data.is_day==1){
            tv_time_limit.setText(data.time_limit+"天");
        }else{
            tv_time_limit.setText(data.time_limit+"个月");
        }
        pb.setProgress(((int) (new Double(data.amount_invested.toString() )/new Double( data.account.toString())*100)));
    //
        tv_money.setText("总金额:"+data.account);

        pb.setProgress((int) (((int) (new Double(data.amount_invested.toString() )/new Double( data.account.toString())*100))));
        ObjectAnimator animator = ObjectAnimator.ofInt(pb, "progress", 0, ((int) (new Double(data.amount_invested.toString() )/new Double( data.account.toString())*100)));
        animator.setDuration(3000);
        animator.start();
//
//
//        Intent intent = new Intent(getContext(), InvestDetailActivity.class);
//        intent.putExtra("borrowId", data.getId());
//
//        getContext().startActivity(intent);
        super.setData(data);

    }
}